//
//  String+Extension.swift
//  SinaImiate
//
//  Created by xiaoming on 16/7/10.
//  Copyright © 2016年 GoodJob. All rights reserved.
//

import Foundation

extension String {
    ///从当前字符串中, 提取链接和文本
    func cz_href() -> (link: String, text: String)? {
        
        ///匹配方案
        let pattern = "<a href=\"(.*?)\".*?>(.*?)</a>"
        
        /// 创建正则表达式, 并且匹配第一项
        guard let regx = try? RegularExpression(pattern: pattern, options: []),
            result = regx.firstMatch(in: self, options: [], range: NSRange(location: 0, length: characters.count))
            else {
            
            return nil
        }
        
        let link = (self as NSString).substring(with: result.range(at: 1))
        let text = (self as NSString).substring(with: result.range(at: 2))
        
        return (link, text)
    }
    
}
